import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
  mode:'history',
  activeClass: 'active',
  linkActiveClass: 'linkActive',
  routes: [
    {
      path: '/',
      redirect: "/login"
    },
    {
      path: '/login',
      name: 'login',
      meta:{title:'登录页'},
      component: ()=> import("@/views/login/Login.vue")
    },
    {
      path: '/home',
      name: 'home',
      meta:{title:'home页'},
      redirect: '/store',
      component: ()=> import("@/views/home/Home.vue"),
      children:[
        {
          path: '/Store',
          name: 'store',
          meta:{title:'store页'},
          component: ()=> import("@/views/store/Store.vue"),
        }
      ]
    },
    {
      path: '/store',
      name: 'store',
      meta:{title:'store页'},
      component: ()=> import("@/views/store/Store.vue")
    },
    {
      path: '/404',
      name: 'error404',
      meta:{title:'404页'},
      component: ()=> import("@/views/error/404.vue")
    },

  ]
})

router.beforeEach((to,from,next)=>{
  console.log('from.hash--'+from.hash,'from.path--'+from.path);
  console.log(from);
  console.log('to.hash--'+to.hash,'to.path--'+to.path);
  console.log('JWTHeaderName--- '+sessionStorage.JWTHeaderName);
  if (to.matched.length == 0){
    console.log(to.matched,to.matched.length);
    next('/404')
  }
  /*if (to.path != '/login'){
      console.log("sessionStorage.JWTHeaderName-----"+sessionStorage.JWTHeaderName === undefined)
    if (sessionStorage.JWTHeaderName === '' || sessionStorage.JWTHeaderName === undefined){
      next('/login')
    }
  }*/
  console.log("to----");
  console.log(to);
  next()
})


export default router;
